package com.liuyucheng.idea_springboot.util;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

public class ReadForListTask implements Runnable {
    private int startSheet;
    private CountDownLatch countDownLatch;
    private Workbook wb;
    private int startRow;
    private int startColumn;
    private List<ArrayList<String>> list;

    ReadForListTask(int startSheet, CountDownLatch countDownLatch, Workbook wb, int startRow, int startColumn, List<ArrayList<String>> list) {
        this.startSheet = startSheet;
        this.countDownLatch = countDownLatch;
        this.wb = wb;
        this.startRow = startRow;
        this.startColumn = startColumn;
        this.list = list;
    }

    public void run() {
        try {
            ArrayList<String> arrlist = null;
            Sheet sheet = this.wb.getSheetAt(this.startSheet);

            for(int rowNum = this.startRow; rowNum <= sheet.getLastRowNum(); ++rowNum) {
                Row row = sheet.getRow(rowNum);
                arrlist = new ArrayList();

                for(int columnNum = this.startColumn; columnNum < row.getLastCellNum(); ++columnNum) {
                    Cell cell = row.getCell(columnNum);
                    arrlist.add(this.getCellValue(cell, cell.getCellType()));
                }

                this.list.add(arrlist);
            }
        } catch (Exception var10) {
        } finally {
            this.countDownLatch.countDown();
        }

    }

    private String getCellValue(Cell rowCell, int rowCellType) {
        String value = "";
        switch(rowCellType) {
            case 1:
                value = rowCell.getStringCellValue();
                break;
            case 2:
                value = rowCell.getCellFormula();
            case 3:
            default:
                break;
            case 4:
                value = String.valueOf(rowCell.getBooleanCellValue());
                break;
            case 5:
                value = ErrorEval.getText(rowCell.getErrorCellValue());
        }

        return value;
    }
}
